package com.yanchi.proxy.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyInvocationHandler implements InvocationHandler {


    private Rent rent;

    public void setRent(Rent rent) {
        this.rent = rent;
    }

    public Object getProxy(){
        return Proxy.newProxyInstance(getClass().getClassLoader(),rent.getClass().getInterfaces(),this);
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        look();
        Object result = method.invoke(rent, args);
        fee();

        return result;
    }

    public void look(){
        System.out.println("中介带看房子！");
    }

    public void fee(){
        System.out.println("中介收中介费！");
    }
}
